<template>
  <div id="cornerComment" v-if="dialogVisible">
    <div class="cornerComment-in">
      <div class="cornerComment-in-title">
        <span>{{commonType==2?'评价任务日志':'任务日志'}}</span>
        <span class="el-icon-circle-close close-Btn-line" @click="closePOpup"></span>
      </div>
      <div class="commentBody">
        <el-form label-width="100px" class="task_common_form">
<!--          // 1 commonType 回复类型，1 完成 2 管理员评论 3日志报告-->
          <el-form-item :label="commonType==2?'回复附件:':'任务附件'" v-if="commonType==1">
            <el-upload
                class="upload-demo"
                :action="$uploadImg"
                :on-remove="handleDocRemove"
                :on-preview="handleDocPreview"
                :on-success="handleDocSuccess"
                :before-upload="beforeAvatarDocUpload"
                accept=".doc,.docx,application/msword,application/vnd.openxmlformats-officedocument.wordprocessingml.document,.pdf,application/pdf,application/vnd.ms-excel,application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
                multiple
                :limit="1">
              <el-button size="small" class="el-icon-upload">点击上传相应文件</el-button>
              <div slot="tip" class="el-upload__tip">上传word, pdf, excel文件</div>
            </el-upload>

          </el-form-item>
          <el-form-item :label="commonType==2?'回复图片:':'任务图片'">
            <el-upload
                :action="$uploadImg"
                list-type="picture-card"
                :limit="9"
                accept=".jpg,.jpeg,.png"
                :on-success="handleSuccess"
                :on-remove="handleRemove">
              <i class="el-icon-plus"></i>
            </el-upload>
            (图片大小不超过2M,支持jpg、png格式，最多可上传9张)
          </el-form-item>
          <el-form-item :label="commonType==2?'回复描述:':'任务描述'" prop="return_time">
            <el-input v-model="textareaVal" placeholder="填写任务回复进程" type="textarea"></el-input>
          </el-form-item>
        </el-form>
      </div>
      <div class="cornerComment-in-footer">
        <el-button @click.native="closePOpup" size="small">取消</el-button>
        <el-button size="small" type="primary" @click="httpSubmit" v-if="commonType==1">完成并提交</el-button>
        <el-button size="small" type="primary" @click="httpSubmit" v-else>确认并提交</el-button>
      </div>
    </div>
  </div>
</template>

<script>
import {taskReport, taskBuildNote, taskEvaluate} from '@/api/admin/task.js'
import {mapGetters} from "vuex";
export default {
  props: ['visible','commonOption','detail','commonType','noteId', 'tabValue'], // noteId 任务人员id
  components: {},
  data() {
    return {
      dialogVisible: this.visible,
      textareaVal: '',
      picImg: [],
      titleName: '',
      file: ''
    }
  },
  watch: {
    visible() {
      this.dialogVisible = this.visible
      if(this.visible){
        console.log('tabValue123123:',this.tabValue)
      }
    }
  },
  computed: {
    ...mapGetters(['configData']),
  },
  created() {
  },
  methods: {
    httpSubmit () {
      let data_ = {}
      if (!this.textareaVal) {
        this.$message.error('请填写回复内容')
        return
      }
      if (Number(this.commonType) === 1) {
        data_.file = this.file
      }
      // 2 管理员评价
      if (Number(this.commonType) === 2) {
        // id 	整型 	必填 	1 	- 	任务分配对象id
        // log_id 	整型 	必填 	1 	- 	任务日志id
        // evaluate 	字符串 	必填 	1 	- 	评价
        // evaluate_pic 	字符串 	必填 	1 	- 	评价图片
        // evaluate_video 	字符串 	必填 	1 	- 	评价视频
        data_.log_id = this.commonOption.commonId // 日志每一条id
        data_.id = this.noteId // 任务成员列表id
        data_.evaluate = this.textareaVal // 评价
        data_.evaluate_pic = this.picImg.join(',') // 评价图片
        data_.evaluate_video = '' // 评价图片
      } else {
        data_.reply = this.textareaVal
        data_.id = this.detail.id
        data_.reply_pic = this.picImg.join(',')
        data_.task_user_id = this.taskUserId
      }
      console.log(data_)
      console.log('提交信息', this.tabValue)
      // 1 commonType 回复类型，1 完成 2 管理员评论 3日志报告
      if (Number(this.commonType) === 1) {
        taskReport({type: this.tabValue, data: data_}).then(data => {
          this.getResponse(data)
        })
      }else if (Number(this.commonType) === 2) {
        taskEvaluate({type: this.tabValue, data: data_}).then(data => {
          this.getResponse(data)
        })
      }else if (Number(this.commonType) === 3) {
        taskBuildNote({type: this.tabValue, data: data_}).then(data => {
          this.getResponse(data)
        })
      }
    },
    getResponse(response){
      if (response.code === 0) {
        this.$message.success('提交成功')
        this.$emit('getUser', 'comment')
        this.closePOpup()
        this.dialogTableVisible = false
        this.textareaVal = ''
        this.picImg = []
      } else {
        this.$message.error(response.msg)
      }
    },
    // 关闭弹窗
    closePOpup() {
      this.$emit('update:visible', false)
    },
    getJson(option) {
      return JSON.parse(JSON.stringify(option))
    },
    handleRemove (file, fileList) {
      let num = this.picImg.indexOf(file.response.data.name)
      this.picImg.splice(num, 1)
    },
    handleSuccess (response, file, fileList) {
      console.log('成功了:', response, file, fileList)
      this.picImg.push(response.data.name)
    },
    beforeAvatarDocUpload (file) {
      console.log('上传数据excel：', file)
    },
    handleDocSuccess (response) {
      this.file = response.data.name
    },
    handleDocPreview (response) {
      console.log('预览:', response.response.data.name)
      console.log('configData:', this.configData.url)

      // window.open( `${this.configData.url}${option.src}`)
      // this.file = response.data.name
    },
    handleDocRemove (file, fileList) {
      console.log('移除', file, fileList)
      this.file = ''
    }
  },
  mounted() {
  }
}
</script>
<style scoped>
#cornerComment {
  height: 100vh;
  width: 100%;
  position: fixed;
  top: 0;
  left: 0;
  background: rgba(0, 0, 0, .5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9;
}

.cornerComment-in {
  width: 55%;
  height: 65%;
  background: #fff;
  display: flex;
  flex-direction: column;
  border-radius: 5px;
}

.cornerComment-in-title {
  height: 50px;
  display: flex;
  align-items: center;
  border-bottom: 1px solid #ddd;
  font-size: 24px;
}

.cornerComment-in-title span {
  padding: 0 10px;
}

.cornerComment-in-title span:first-child {
  flex: 1;
  font-size: 16px;
}

.cornerComment-in-footer {
  height: 50px;
  border-top: 1px solid #ddd;
  display: flex;
  align-items: center;
  padding: 0 10px;
  justify-content: center;
}

.commentBody {
  padding:20px;
  flex: 1;
  overflow-y: auto;
}

.close-Btn-line {
  cursor: pointer;
}

.resruitment-title {
  padding: 5px 0;
  border-bottom: 2px solid #abd3f3;
  margin-bottom: 20px;
}

.el-radio {
  margin-right: 20px;
}

.jobTime {
  display: flex;
  align-items: center;
}

.jobTime span {
  padding: 0 10px;
}
</style>


